package com.epfresh.supplier.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.epfresh.api.adapter.CommonAdapter;
import com.epfresh.api.adapter.ViewHolder;
import com.epfresh.api.constant.AppSupplyRouterConstant;
import com.epfresh.api.entity.RequestEntitySupply;
import com.epfresh.api.entity.ResponseEntity;
import com.epfresh.api.global.BaseActivity;
import com.epfresh.api.global.BaseApplication;
import com.epfresh.api.http.OnRequestListener;
import com.epfresh.api.utils.FormatUtil;
import com.epfresh.api.utils.T;
import com.epfresh.api.widget.NoScrollListView;
import com.epfresh.api.widget.lines.SegmentLines;
import com.epfresh.api.widget.lines.Unit;
import com.epfresh.supplier.R;
import com.epfresh.supplier.adapter.BookBestAdapter;
import com.epfresh.supplier.dialog.BookProgressDialog;
import com.epfresh.supplier.entity.BookInfoEntity;
import com.epfresh.supplier.entity.DealDetailEntity;
import com.google.gson.Gson;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BookActivity extends BaseActivity {

    private View rl_money_detail,iv_book_triangle;
    private TextView tv_1_, tv_2_, tv_3_, tv_4_;
    private TextView txt_month_total;


    private TextView tv_sum_new, tv_done_new, tvTime, tvDealTime;
    SegmentLines segmentLines;
    View tvMoreBest, ivTime, tvMoreAlready;
    TextView tvMoreDetail;
    NoScrollListView lv_deal_detail, lv_deal_best, lv_deal_already;

    View llAlready;
    int timeYearFlag = 1; //年月类型；1：月；2：年
    String timeString = "";//年月字符串；年:"2017"；月:"20174-04"
    public String timeTitle = "";


    ArrayList<DealDetailEntity.ContentBean> detailList = new ArrayList<>();
    ArrayList<BookInfoEntity.DetailListBean> alreadyList = new ArrayList<>();

    DetailAdapter detailAdapter;
    BookBestAdapter bestAdapter;

    AlreadyAdapter alreadyAdapter;
    ArrayList<BookInfoEntity.ProductListBean> bestList = new ArrayList<>();

    BookInfoEntity.SettledFeeOver settledFeeOver;


    View rlTime;
    ListView lvTime;
    TimeAdapter timeAdapter;
    ArrayList<BookInfoEntity.QueryDateListBean> timeList = new ArrayList<>();

    int timePosition;
    View iv_left;
    View iv_right;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_book);
//        findViewById(R.id.tv_info).setOnClickListener(this);
        rl_money_detail = findViewById(R.id.rl_money_detail);
        rl_money_detail.setOnClickListener(this);
        iv_book_triangle = findViewById(R.id.iv_book_triangle);
        tv_1_ = (TextView) findViewById(R.id.tv_1_);
        tv_2_ = (TextView) findViewById(R.id.tv_2_);
        tv_3_ = (TextView) findViewById(R.id.tv_3_);
        tv_4_ = (TextView) findViewById(R.id.tv_4_);

        ivBack.setVisibility(View.VISIBLE);
        ivBack.setImageResource(R.mipmap.title_left_white);
        actionbar.setBackgroundResource(R.color.colorPrimaryDarkBook);
        actionbar.findViewById(R.id.v_line).setVisibility(View.GONE);
        toolbarTitle.setTextColor(Color.WHITE);
        rightbtn.setTextColor(Color.WHITE);
        toolbarTitle.setText("我的收入");

        lv_deal_detail = (NoScrollListView) findViewById(R.id.lv_deal_detail);
        lv_deal_best = (NoScrollListView) findViewById(R.id.lv_deal_best);

        txt_month_total = findViewById(R.id.txt_month_total);
        lv_deal_already = (NoScrollListView) findViewById(R.id.lv_deal_already);
        llAlready = findViewById(R.id.ll_already);
        alreadyAdapter = new AlreadyAdapter(this, alreadyList, R.layout.item_book_detail);
        detailAdapter = new DetailAdapter(this, detailList, R.layout.item_book_detail_new);
        lv_deal_detail.setAdapter(detailAdapter);
        lv_deal_already.setAdapter(alreadyAdapter);


        tv_done_new = (TextView) findViewById(R.id.tv_done_new);
        tv_done_new.setOnClickListener(this);
        tv_sum_new = (TextView) findViewById(R.id.tv_sum_new);
        tvTime = (TextView) findViewById(R.id.tv_time);
        tvDealTime = (TextView) findViewById(R.id.tv_deal_time);

        tvMoreAlready = findViewById(R.id.tv_more_already);
        tvMoreBest = findViewById(R.id.tv_more_best);
        tvMoreDetail = (TextView)findViewById(R.id.tv_more_detail);
        ivTime = findViewById(R.id.iv_time);

        tvMoreAlready.setOnClickListener(this);
        tvMoreBest.setOnClickListener(this);
        ivTime.setOnClickListener(this);
        tvMoreDetail.setOnClickListener(this);

        rlTime = findViewById(R.id.rl_time);
        lvTime = (ListView) findViewById(R.id.lv_time);
        timeAdapter = new TimeAdapter(this, timeList, R.layout.item_string_book_old);
        lvTime.setAdapter(timeAdapter);
        rlTime.setOnClickListener(this);
        iv_left = findViewById(R.id.iv_left);
        iv_right = findViewById(R.id.iv_right);
        iv_right.setOnClickListener(this);
        iv_left.setOnClickListener(this);


        segmentLines = (SegmentLines) findViewById(R.id.segment_line);
        mHttpLoad();
    }

    private void initSegment() {
        if (data == null) {
            segmentLines.setVisibility(View.INVISIBLE);
            return;
        }
        List<Unit> lines = new ArrayList<>();
        List<BookInfoEntity.TrendListBean> trendList = data.getTrendList();
        int position = 0;
        boolean isFirstPoint = false;
        if(trendList == null || trendList.size() == 0){
            segmentLines.setVisibility(View.INVISIBLE);
        }
        if (trendList != null && trendList.size() > 0) {
            if (trendList.size() < 5) {
                segmentLines.setVisibility(View.INVISIBLE);
                return;
            }
            segmentLines.setVisibility(View.VISIBLE);
            position = trendList.size() - 1;
            for (int i = 0; i < trendList.size(); i++) {
                BookInfoEntity.TrendListBean trendListBean = trendList.get(i);

                if (trendListBean != null) {
                    String name = trendListBean.getName();
                    String type = trendListBean.getType();
                    String price = trendListBean.getPrice();
                    double priceY = trendListBean.getPriceY();
                    String queryDate = trendListBean.getQueryDate();

//                    priceY = 0.85;
//                    price = "0.85";
                    if ("1".equals(type)) {
                        lines.add(new Unit((float) priceY, name, price));
                    } else if ("0".equals(type)) {
                        if (!isFirstPoint) {
                            isFirstPoint = true;
                            if (i > 0) {
                                position = i - 1;
                            }
                            lines.add(new Unit((float) priceY, name, price, 1));
                        } else {
                            lines.add(new Unit((float) priceY, name, price, 1));
                        }
                    }
                }
            }
        } else {
            return;
        }
        if (position < lines.size()) {
            Unit unit = lines.get(position);
            unit.setPointType(2);
        }

        segmentLines.feed(lines, position);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        Object o;
        int position = 0;
        switch (view.getId()) {
//            case R.id.tv_info:
//                final BookProgressDialog dialog = new BookProgressDialog(mContext);
//                dialog.setOnSureListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        dialog.dismiss();
//                    }
//                });
//                dialog.show();
//                break;
            case R.id.rl_money_detail:
                rl_money_detail.setVisibility(View.GONE);
                iv_book_triangle.setVisibility(View.GONE);
                break;
            case R.id.tv_done_new:
                if(rl_money_detail.getVisibility()==View.VISIBLE){
                    rl_money_detail.setVisibility(View.GONE);
                    iv_book_triangle.setVisibility(View.GONE);
                }else {
                    rl_money_detail.setVisibility(View.VISIBLE);
                    iv_book_triangle.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.iv_right:
                rlTime.setVisibility(View.GONE);
                if(timePosition<=0){

                }else{

                    timePosition--;
                    timeString = timeList.get(timePosition).getQueryDate();
                    //tvTime.setText(timeList.get(timePosition).getName());
                    if (timeList.get(timePosition).getName().contains("月")) {
                        timeYearFlag = 1;
                    } else {
                        timeYearFlag = 2;
                    }
                    if(timePosition == 0){
                        iv_right.setVisibility(View.GONE);
                    }else{
                        iv_right.setVisibility(View.VISIBLE);
                    }
                    if(timePosition == timeList.size()-1 ){
                        iv_left.setVisibility(View.GONE);
                    }else {
                        iv_left.setVisibility(View.VISIBLE);
                    }
                    mHttpLoad();
                }
                break;
            case R.id.iv_left:
                rlTime.setVisibility(View.GONE);
                if(timePosition>=timeList.size()-1){

                }else{
                    timePosition++;
                    timeString = timeList.get(timePosition).getQueryDate();
                    //tvTime.setText(timeList.get(timePosition).getName());
                    if (timeList.get(timePosition).getName().contains("月")) {
                        timeYearFlag = 1;
                    } else {
                        timeYearFlag = 2;
                    }
                    if(timePosition == 0){
                        iv_right.setVisibility(View.GONE);
                    }else{
                        iv_right.setVisibility(View.VISIBLE);
                    }
                    if(timePosition == timeList.size()-1 ){
                        iv_left.setVisibility(View.GONE);
                    }else {
                        iv_left.setVisibility(View.VISIBLE);
                    }
                    mHttpLoad();
                }
                break;
            case R.id.ll_best_item:
                o = view.getTag(R.id.item_key_position);
                if (o != null && o instanceof Integer) {
                    position = (int) o;
                    if(timeYearFlag==2) {
                        Intent detailIntent = new Intent(this,
                                BookGoodsYearActivity.class);
                        detailIntent.putExtra("timeTitle", timeTitle);
                        detailIntent.putExtra("timeValue", bestList.get(position).getQueryDate());
                        detailIntent.putExtra("money", FormatUtil.formatDecimal(bestList.get(position).getPrice()) + "元");
                        detailIntent.putExtra("productId", bestList.get(position).getSpecId());
                        startActivity(detailIntent);
                    }else{
                        Intent detailIntent = new Intent(this,
                                BookGoodsMonthActivity.class);
                        detailIntent.putExtra("timeTitle", timeTitle);
                        detailIntent.putExtra("timeValue", bestList.get(position).getQueryDate());
                        detailIntent.putExtra("money", "" + FormatUtil.formatDecimal(bestList.get(position).getPrice()) + "元");
                        detailIntent.putExtra("productId", bestList.get(position).getSpecId());
                        startActivity(detailIntent);
                    }
                }
                break;
            case R.id.rl_time:
                rlTime.setVisibility(View.GONE);
                break;
            case R.id.iv_time:
                // 返回上一页
                if (rlTime.getVisibility() == View.VISIBLE) {
                    rlTime.setVisibility(View.GONE);
                } else {
                    rlTime.setVisibility(View.VISIBLE);
                    timeAdapter.notifyDataSetChanged();
                }
                break;
            case R.id.tv_more_best:
                Intent bestIntent = new Intent(mContext,
                        BookBestMoreActivity.class);
                bestIntent.putExtra("timeTitle", tvTime.getText().toString());
                bestIntent.putExtra("timeValue", timeString);
                bestIntent.putExtra("money", data.getQueryTotleIncome());
                startActivity(bestIntent);
                break;
            case R.id.tv_more_detail:
                if (timeYearFlag == 1) {
                    Intent detailIntent = new Intent(mContext, BookDetailMonthActivity.class);
                    detailIntent.putExtra("timeValue", timeString);
//                    detailIntent.putExtra("detailList", (Serializable) detailList);
                    startActivity(detailIntent);
                }
                break;
            case R.id.tv_more_already:
                if (timeYearFlag == 1) {
                    Intent detailIntent = new Intent(mContext,
                            BookAlreadyMonthActivity.class);
                    detailIntent.putExtra("timeTitle", tvTime.getText().toString());
                    detailIntent.putExtra("timeValue", timeString);
                    detailIntent.putExtra("money", FormatUtil.formatDecimal(data.getQueryTotleIncome()));
                    detailIntent.putExtra("detailList", (Serializable) alreadyList);
                    startActivity(detailIntent);
                }
                break;
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

    /**
     * 加载台账数据
     */
    private void mHttpLoad() {
        RequestEntitySupply<Map<String, String>> data = new RequestEntitySupply<>();
        data.setCmd(com.epfresh.api.constant.AppSupplyRouterConstant.cmd_order_supplier_order_incomeMain);
        Map<String, String> map = new HashMap<>();
        map.put("storeId", BaseApplication.getInstance().getStoreId());

        map.put("isDc", "" + (getStoreInfo().isDc() ? 1 : 0));
        map.put("queryDate", timeString);
        map.put("accountId", getUser().getAccountId());
        map.put("type", "" + timeYearFlag);
        data.setParameters(map);
        request(data, com.epfresh.api.constant.AppSupplyRouterConstant.cmd_order_supplier_order_incomeMain, onRequestListener);
    }

    BookInfoEntity data;
    private OnRequestListener<BookInfoEntity> onRequestListener = new OnRequestListener<BookInfoEntity>() {
        @Override
        public BookInfoEntity jsonToObj(String responseStr) {
            return new Gson().fromJson(responseStr, BookInfoEntity.class);
        }

        @Override
        public void onFail(int failCode, Object arg, Object tag) {
            hideProgressDialog();
        }

        @Override
        public void onResponseError(int failCode, Object arg, Object tag) {
            hideProgressDialog();
        }

        @Override
        public void onStart(Object tag) {
            showProgressDialog();
        }

        @Override
        public void onResponse(ResponseEntity<BookInfoEntity> response, Object tag) {

            hideProgressDialog();
            BookInfoEntity responseElement = response.getResponseElement();
            reqDealDetail(responseElement.getQueryDate());
            data = responseElement;

            tv_1_.setText(data.getTollFreeFeeOver());
            tv_2_.setText(data.getSettledServiceFee());
            tv_3_.setText(data.getTollFreeFee());
            tv_4_.setText(data.getNoSettleServiceFee());

            TextView tv_now_new = (TextView)findViewById(R.id.tv_now_new);
            tv_now_new.setText(FormatUtil.formatDecimal(data.getTodayIncome()));

            timeString = responseElement.getQueryDate();
            if (responseElement.getSettledFeeOver() != null) {
                String queryDateTitle = responseElement.getQueryDateTitle();
                String month = queryDateTitle.substring(5);
                txt_month_total.setText(month + "合计:" + responseElement.getSettledFeeOver().getTotalFee());
            }

            //tvDealTime.setText(responseElement.getQueryDate());
            tvTime.setText(responseElement.getQueryDateTitle());
            //bestAdapter.colorLengthFlag = responseElement.getQueryTotleIncome();
            bestList.clear();

            timeTitle = responseElement.getQueryDateTitle();

            timeList.clear();
            bestList.addAll(responseElement.getProductList());
            bestAdapter = new BookBestAdapter(mContext, bestList);//, responseElement.getQueryTotleIncome());
            lv_deal_best.setFocusable(false);
            bestAdapter.setOnItemClickListener(BookActivity.this);
            lv_deal_best.setAdapter(bestAdapter);
            bestAdapter.notifyDataSetChanged();


            settledFeeOver = data.getSettledFeeOver();

            if(timeYearFlag == 2 || settledFeeOver ==null || settledFeeOver.getContent() == null || settledFeeOver.getContent().size()==0){
                llAlready.setVisibility(View.GONE);
            }else{
                Log.e("settledFeeOver",settledFeeOver+";"+"settledFeeOver.content:"+settledFeeOver.getContent()+"settledFeeOver.size:"+settledFeeOver.getContent().size());
                llAlready.setVisibility(View.VISIBLE);
                alreadyList.clear();
                alreadyList.addAll(settledFeeOver.getContent());
                if(settledFeeOver.getContent().size()>7){
                    tvMoreAlready.setVisibility(View.VISIBLE);
                }else {
                    tvMoreAlready.setVisibility(View.GONE);
                }
                alreadyAdapter.notifyDataSetChanged();
            }

            if(responseElement.getProductIsMore()==1){
                tvMoreBest.setVisibility(View.VISIBLE);
            }else {
                tvMoreBest.setVisibility(View.GONE);
            }

/*
            if (timeYearFlag == 2) {//年的详情数据显示全部；月的详情，最多七条，超过了显示更多；
                tvMoreDetail.setVisibility(View.GONE);
                detailList.addAll(responseElement.getDetailList());
            } else {
                if (responseElement.getDetailList().size() <= 7) {
                    tvMoreDetail.setVisibility(View.GONE);
                    detailList.addAll(responseElement.getDetailList());
                } else {
                    detailList.addAll(responseElement.getDetailList());
                    tvMoreDetail.setVisibility(View.VISIBLE);
                }
            }
*/

            if (timeYearFlag == 2) {//年的详情数据显示全部；月的详情，最多七条，超过了显示更多；
                //tvMoreDetail.setVisibility(View.GONE);
                tvMoreDetail.setText("没有更多了");
                tvMoreDetail.setClickable(false);
            } else {
                if (responseElement.getDetailList().size() <= 7) {
                    //tvMoreDetail.setVisibility(View.GONE);
                    tvMoreDetail.setText("没有更多了");
                    tvMoreDetail.setClickable(false);
                } else {
                    //tvMoreDetail.setVisibility(View.VISIBLE);
                    tvMoreDetail.setText("查看更多");
                    tvMoreDetail.setClickable(true);
                }
            }
//            detailList.addAll(responseElement.getDetailList());

            for (int i = 0; i < responseElement.getQueryDateList().size(); i++) {
                timeList.add(responseElement.getQueryDateList().get(i));
                timeList.addAll(responseElement.getQueryDateList().get(i).getChild());
            }
            timeAdapter.notifyDataSetChanged();
            initSegment();
            tv_sum_new.setText(FormatUtil.formatDecimal(responseElement.getAllIncome()));
            if(responseElement.getAllIncome()==null){
                responseElement.setAllIncome(0.0);
            }
            tv_done_new.setText(FormatUtil.formatDecimal(responseElement.getAllIncomeSuccess()));

            if(bestList.size()==0){
                findViewById(R.id.tv_best_info).setVisibility(View.GONE);
                lv_deal_best.setVisibility(View.GONE);
            }else {
                findViewById(R.id.tv_best_info).setVisibility(View.VISIBLE);
                lv_deal_best.setVisibility(View.VISIBLE);
            }

            for(int i=0;i<timeList.size();i++){
                if(timeList.get(i).getQueryDate().equals(responseElement.getQueryDate())){
                    timePosition = i;
                    return;
                }
            }
        }
    };

    void toMonthDetail(int position){
        Intent detailIntent = new Intent(mContext, BookDetailMonthActivity.class);
        //detailIntent.putExtra("timeTitle", timeList.get(timePosition).getName()+tvTime.getText().toString());
        detailIntent.putExtra("timeValue", detailList.get(position).getDateStr());
//        detailIntent.putExtra("money", FormatUtil.formatDecimal(detailList.get(position).getReceivableAmount()));
        //detailIntent.putExtra("detailList", (Serializable) detailList);
        startActivity(detailIntent);
    }

    class DetailAdapter extends CommonAdapter<DealDetailEntity.ContentBean> implements View.OnClickListener {
        public DetailAdapter(Context context, ArrayList<DealDetailEntity.ContentBean> runPacks, int a) {
            super(context, runPacks, a);
        }

        public void onClick(View v) {
            Object tag = v.getTag(R.id.item_key_position);
            if (tag != null && tag instanceof Integer) {
                int position = (int) tag;
                if (timeYearFlag == 2) {
                    toMonthDetail(position);
                } else {
                    Intent detailIntent = new Intent(mContext, BookDetailDayActivity.class);
                    detailIntent.putExtra("timeTitle", detailList.get(position).getDay());
                    detailIntent.putExtra("timeValue", detailList.get(position).getDateStr());
                    startActivity(detailIntent);
                }
            }
        }

        @Override
        public int getCount() {
            if (mDatas == null) {
                return 0;
            }
            if (timeYearFlag == 1 && mDatas.size() > 7) {
                return 7;
            } else {
                return mDatas.size();
            }
        }

        @Override
        public void convert(final ViewHolder holder, final DealDetailEntity.ContentBean bean) {
            holder.getView(R.id.ll_item).setTag(R.id.item_key_position, detailList.indexOf(bean));
            holder.setOnClickListener(R.id.ll_item, this);
            holder.setText(R.id.tv_time, bean.getDay());
//            holder.setText(R.id.tv_money, FormatUtil.formatDecimal(bean.getPrice()));
//            holder.setText(R.id.tv_number, bean.getSettleProgress());
//            holder.setText(R.id.tv_money_serve, bean.getSettledServiceFee());
            holder.setText(R.id.tv_money_should, bean.getReceivableAmount());
            holder.setText(R.id.tv_money_already,bean.getSettledAmount());
            if(holder.getPosition()%2==1){
                holder.getView(R.id.ll_item).setBackgroundColor(Color.WHITE);
            }else {
                holder.getView(R.id.ll_item).setBackgroundColor(Color.parseColor("#fcfcfc"));
            }
        }
    }


    class TimeAdapter extends CommonAdapter<BookInfoEntity.QueryDateListBean> implements View.OnClickListener {
        public TimeAdapter(Context context, ArrayList<BookInfoEntity.QueryDateListBean> runPacks, int a) {
            super(context, runPacks, a);
        }

        public void onClick(View v) {
            Object tag = v.getTag(R.id.item_key_position);
            if (tag != null && tag instanceof Integer) {
                timePosition = (int) tag;
                rlTime.setVisibility(View.GONE);
                if (timeString.equals(timeList.get(timePosition).getName())) {
                    return;//如果点选的是当前时间，直接取消对话框即可
                }
                if (timeList.get(timePosition).getQueryDate().length() == 4) {
                    timeYearFlag = 2;
                } else {
                    timeYearFlag = 1;
                }
                timeString = timeList.get(timePosition).getQueryDate();
                if(timePosition == 0){
                    iv_right.setVisibility(View.GONE);
                }else{
                    iv_right.setVisibility(View.VISIBLE);
                }
                if(timePosition == timeList.size()-1 ){
                    iv_left.setVisibility(View.GONE);
                }else {
                    iv_left.setVisibility(View.VISIBLE);
                }
                mHttpLoad();
            }
        }

        @Override
        public void convert(final ViewHolder holder, final BookInfoEntity.QueryDateListBean bean) {
            holder.getView(R.id.tv_string).setTag(R.id.item_key_position, timeList.indexOf(bean));
            holder.setOnClickListener(R.id.tv_string, this);
            holder.setText(R.id.tv_string, bean.getName());
            if(timeList.indexOf(bean)==timePosition){
                holder.getView(R.id.v_flag).setVisibility(View.VISIBLE);
                ((TextView)holder.getView(R.id.tv_string)).setTextColor(Color.RED);
            }else{
                holder.getView(R.id.v_flag).setVisibility(View.INVISIBLE);
                ((TextView)holder.getView(R.id.tv_string)).setTextColor(Color.parseColor("#434343"));
            }
        }
    }


    class AlreadyAdapter extends CommonAdapter<BookInfoEntity.DetailListBean> implements View.OnClickListener {
        public AlreadyAdapter(Context context, ArrayList<BookInfoEntity.DetailListBean> runPacks, int a) {
            super(context, runPacks, a);
        }

        public void onClick(View v) {
            Object tag = v.getTag(R.id.item_key_position);
            if (tag != null && tag instanceof Integer) {
                int position = (int) tag;
                Intent detailIntent = new Intent(mContext,
                        BookAlreadyListActivity.class);
                detailIntent.putExtra("timeTitle", alreadyList.get(position).getDateStr());
                detailIntent.putExtra("timeValue", alreadyList.get(position).getQueryDate());
                startActivity(detailIntent);
            }
        }

        @Override
        public int getCount() {
            if (mDatas == null) {
                return 0;
            }
            if (timeYearFlag == 1 && mDatas.size() > 7) {
                return 7;
            } else {
                return mDatas.size();
            }
        }

        @Override
        public void convert(final ViewHolder holder, final BookInfoEntity.DetailListBean bean) {
            holder.getView(R.id.ll_item).setTag(R.id.item_key_position, alreadyList.indexOf(bean));
            holder.setOnClickListener(R.id.ll_item, this);
            holder.setText(R.id.tv_time, bean.getDateStr());
            holder.setText(R.id.tv_money, bean.getTotalFee() + "元");
        }
    }

    /**
     * 请求获取交易明细信息
     */
    private void reqDealDetail(String queryDate) {
        RequestEntitySupply<Map<String,Object>> requestEntitySupply = new RequestEntitySupply<>();
        Map<String,Object> map = new HashMap<>();
        map.put("storeId",BaseApplication.getInstance().getStoreId());
        map.put("authNeedBind",BaseApplication.getInstance().getMerchant().isAuthNeedBind());
        map.put("queryDate",queryDate);
        requestEntitySupply.setParameters(map);
        requestEntitySupply.setCmd(AppSupplyRouterConstant.cmd_finance_settle_income_orderTable);
        request(requestEntitySupply,AppSupplyRouterConstant.cmd_finance_settle_income_orderTable,onRequestDealDetailListener);
    }

    private OnRequestListener<DealDetailEntity> onRequestDealDetailListener = new OnRequestListener<DealDetailEntity>() {
        @Override
        public DealDetailEntity jsonToObj(String responseStr) {
            return new Gson().fromJson(responseStr,DealDetailEntity.class);
        }

        @Override
        public void onFail(int failCode, Object arg, Object tag) {
        }

        @Override
        public void onResponseError(int failCode, Object arg, Object tag) {
        }

        @Override
        public void onStart(Object tag) {

        }

        @Override
        public void onResponse(ResponseEntity<DealDetailEntity> response, Object tag) {
            DealDetailEntity dealDetailEntity = response.getResponseElement();
            detailList.clear();
            detailList.addAll(dealDetailEntity.getContent());
            if(detailList.size()==0){
                //findViewById(R.id.tv_detail_info).setVisibility(View.GONE);
                findViewById(R.id.tv_detail_info_five).setVisibility(View.GONE);
                lv_deal_detail.setVisibility(View.GONE);
            }else{
                //findViewById(R.id.tv_detail_info).setVisibility(View.VISIBLE);
                findViewById(R.id.tv_detail_info_five).setVisibility(View.VISIBLE);
                lv_deal_detail.setVisibility(View.VISIBLE);
            }
            detailAdapter.notifyDataSetChanged();
        }
    };
}
